$(function () {
    $("#huozhu").keyup(function () {
        $.ajax({
            type:"get",
            url:"getManyHuozhu.do",
            data:"custName="+$("#huozhu").val(),
            success:function (data) {
                $("#table").html('');
                $("#table").append("<tr><td>客户id<td/>" +
                    "<td>客户名称<td/>" +
                    "<td>客户手机<td/>" +
                    "<td>客户电话<td/></tr>")
                for (var i=0;i<data.length;i++)
                {
                    $("#table").append("<tr id='tr' onmouseout='change(this)' onmouseover='over(this)' onclick='dianJi(\""+data[i].custId+"\",\""+data[i].custName+"\")' >" +
                        "<td>"+data[i].custId+"<td/>" +
                        "<td>"+data[i].custName+"<td/>" +
                        "<td>"+data[i].custIcChip+"<td/>" +
                        "<td>"+data[i].custTel+"<td/></tr>")
                }
            }
        })
    })
})
function dianJi(custId,custName) {
    $.ajax({
        type: "get",
        url:"getManyMingxi.do",
        data:"custId="+custId,
        dataType:"json",
        success:function (data) {
            $("#tbody").html("")
            var want = custId+"-"+custName;
            //2 输入框的内容是你点击的div的内容
            $("#huozhu").val(want);
            //1 让下方table内容清空
            $("#table").html("");
            var zongzhongliang = 0;
            for (var i=0;i<data.length;i++)
            {
                var zhongliang = data[i].detailsGoodsSpec*data[i].detailsGoodsNum
                $("#tbody").append("<tr>" +
                    "<td>"+data[i].trayId+"</td>" +
                    "<td>"+data[i].detailsGoodsName+"</td>" +
                    "<td>"+data[i].detailsGoodsSpec+"</td>" +
                    "<td>"+data[i].currentGoodsNum+"</td>" +
                    "<td>"+data[i].detailsGoodsNum+"</td>" +
                    "<td>"+zhongliang+"</td></tr>")
                zongzhongliang=zongzhongliang+zhongliang;
            }

            $("#geshu").val(data.length);
            $("#zongzhongliang").val(zongzhongliang);
        }
    })

}
function over(tr) {
    tr.style.backgroundColor="hsl(176,45%,43%)"
}
function change(tr) {
    tr.style.backgroundColor="white"
}